package com.wcq.studentbackend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wcq.studentbackend.dto.ClassStudentCountDTO;
import com.wcq.studentbackend.entity.Class;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 班级表 Mapper 接口
 * </p>
 *
 * @author Gemini
 * @since ${.now?date}
 */
@Mapper // 或者在启动类上使用 @MapperScan("com.wcq.studentbackend.mapper")
public interface ClassMapper extends BaseMapper<Class> {

    @Select("""
            SELECT 
                c.class_name AS className,
                COUNT(s.id) AS studentCount
            FROM 
                classes c
            LEFT JOIN 
                students s ON c.id = s.class_id
            GROUP BY 
                c.id, c.class_name
            ORDER BY 
                c.class_name
            """)
    List<ClassStudentCountDTO> getClassStudentCounts();

} 